<?php

function apply_template($tpl_file, $vars = array(), $include_globals = true)
{
  extract($vars);

  if ($include_globals) extract($GLOBALS, EXTR_SKIP);

  ob_start(); // Start output buffering

  require($tpl_file);

  $applied_template = ob_get_contents();
  ob_end_clean();

  return $applied_template;
}

function apply_transformation($xsl, $xml, $vars = array(), $include_globals = false)
{
  $xsl_doc = new DOMDocument();
  $xsl_proc = new XSLTProcessor();

  $xsl_doc->load($xsl); // TODO: Support loading from string
  $xsl_proc->importStyleSheet($xsl_doc);


  $xml_doc = new DOMDocument();
  $xml_doc->load($xml);

  return $xsl->transformToXML($xml_doc);
}

?>
